package bje;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * JUnit tests for the amount of bullet power calculated by the robot Surfer method calcFirePower.
 * 
 * @author Jeffrey Beck
 */
public class TestCalcFirePower {

  /** The JUnit maximum allowable difference in the calls to assertEquals using doubles as args. **/
  private static double DELTA = 0.01;

  /**
   * Uses equivalence class partitioning to test calculation of fire power based on various
   * distances to enemy robots and battlefield widths. The amount calculated should be between 0.1
   * and 3. The argument to calcFirePower are the battlefield width and the distance to the enemy.
   * The function returns the minimum of (fieldWidth / distance) or 3. In the comments below, "val"
   * refers to the value calculated by calcFirePower, and the function returns the minimum of "val"
   * and 3.0.
   */
  @Test
  public void testCalcFirePower() {
    Surfer surfer = new Surfer();

    assertEquals("Test possible divide by zero, expect 1.0", 1.0, surfer.calcFirePower(0, 0), 
        DELTA);
    assertEquals("Test value and max the same, expect 3.0", 3.0, surfer.calcFirePower(600, 200),
        DELTA);
    assertEquals("Test value (4) > max, expect 3.0", 3.0, surfer.calcFirePower(800, 200), DELTA);
    assertEquals("Test value(.25), expect 0.25", 0.25, surfer.calcFirePower(200, 800), DELTA);
    assertEquals("Test value (0.01), expect 0.1", 0.1, surfer.calcFirePower(100, 10000), DELTA);

  }

}